package light.head.dao.mobile;

import java.util.ArrayList;
import java.util.List;

import light.head.framework.base.BaseDAO;
import light.head.model.Photo;

import org.springframework.stereotype.Service;

@Service
public class MobilePhotoDAO extends BaseDAO<Photo, Integer> {
	
	private final static String sql_findByAlc = "FROM Photo p WHERE p.alc = ? AND p.deleted = 0";
	
	/**
	 * 通过相册编号获取该相册的所有相片
	 *@param alc	相册编号
	 *@author yangguanghe [2014-5-27_下午5:14:33]
	 */
	public List<Photo> findByAlc(Integer alc) {
		if (null == alc) return null;
		return find(sql_findByAlc, alc);
	}
	
	/**
	 * 通过相册编号集合查询出所有的相片
	 *@param alcs	相册编号集合
	 *@author yangguanghe [2014-5-27_下午5:20:09]
	 */
	public List<Photo> findByAlc(List<Integer> alcs) {
		if (null == alcs || alcs.size() == 0) return null;
		
		StringBuffer hql = new StringBuffer("FROM Photo p WHERE p.deleted = 0 AND p.alc IN (");
		
		List<Object> parm = new ArrayList<Object>();
		
		for (Integer i : alcs) {
			if (null == i) continue;
			parm.add(i);
			hql.append("?,");
		}
		hql.deleteCharAt(hql.length() - 1).append(")");
		
		return find(sql_findByAlc, parm.toString());
	}
	


}
